﻿using System;
using System.Collections.Generic;
using System.Management.Automation;
using Microsoft.SharePoint;
using Microsoft.SharePoint.PowerShell;
using Microsoft.SharePoint.Administration;
using System.Globalization;
using System.ComponentModel;
using System.Security.Principal;
using System.Collections.Specialized;
using System.Linq;
using Microsoft.SharePoint.Utilities;


namespace SlamCms.SharePoint.PowerShell
{
	[Cmdlet(VerbsCommon.Copy, "SiteStructure")]
	public class SpCmdletCopySiteStructure : SPCmdlet
	{
        [Parameter(Mandatory = true)]
        public string SourceSiteUrl
        {
            get;
            set;
        }

        [Parameter(Mandatory = true)]
        public string DestinationSiteUrl
        {
            get;
            set;
        }
  

		protected override void InternalValidate()
		{
			if (String.IsNullOrEmpty(SourceSiteUrl) || String.IsNullOrEmpty(DestinationSiteUrl))
			{
				//base.WriteError(new PSArgumentNullException("ListName", "ListName or ContentTypeName must be specified."), ErrorCategory.InvalidArgument, null);
                base.WriteError(new PSArgumentNullException("SourceSiteUrl","SourceSiteUrl and DestinationSiteUrl must be specified"),ErrorCategory.InvalidArgument,null);
				base.SkipProcessCurrentRecord();
			}
		}

        protected override void InternalProcessRecord()
        {
            try
            {
                WriteObject("Beginning site copy structure from: " + SourceSiteUrl + " to: " + DestinationSiteUrl);
                PublishingSiteService.CopySite(SourceSiteUrl, DestinationSiteUrl);
            }
            catch (Exception ex)
            {
                WriteObject("There was an error during the process.");
                WriteObject(ex.Message);
            }

        }
	}
}
